package todo_app

type tTodoEventSerializer struct {
}

func newEventSeiralizer() iTodoEventSerializer {
	it := new(tTodoEventSerializer)
	return it
}

func (me *tTodoEventSerializer) serializeWithTag(tag int, v interface{}) *tJSONData {
	it := new(tJSONData)
	err := it.Set(TagCreated, v)
	if err != nil {
		return nil
	}
	return it
}

func (me *tTodoEventSerializer) SerializeCreatedEvent(e *TodoCreatedEvent) *tJSONData {
	return me.serializeWithTag(TagCreated, e)
}

func (me *tTodoEventSerializer) SerializeUpdatedEvent(e *TodoUpdatedEvent) *tJSONData {
	return me.serializeWithTag(TagUpdated, e)
}

func (me *tTodoEventSerializer) SerializeRemovedEvent(e *TodoRemovedEvent) *tJSONData {
	return me.serializeWithTag(TagRemoved, e)
}

const TagCreated = 1
const TagUpdated = 2
const TagRemoved = 3

var gDefaultEventSerializer = newEventSeiralizer()
